// HotKeyInfo.cpp: implementation of the CHotKeyInfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CStudyChinese.h"
#include "HotKeyInfo.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CHotKeyInfo::CHotKeyInfo()
{
	m_wModifiers = 0 ;
	m_wVirtualKeyCode = 0 ;
	m_bChanged = TRUE ;
}

CHotKeyInfo::~CHotKeyInfo()
{

}

BOOL CHotKeyInfo::IsSame(const CHotKeyInfo &hk)
{
	if(m_wModifiers == hk.m_wModifiers && m_wVirtualKeyCode == hk.m_wVirtualKeyCode)
		return TRUE ;

	return FALSE ;
}

void CHotKeyInfo::UpdateHotKey(const CHotKeyInfo &hk)
{
	m_wModifiers = hk.m_wModifiers ;
	m_wVirtualKeyCode = hk.m_wVirtualKeyCode ;
	m_bChanged = TRUE ;
}

BOOL CHotKeyInfo::RegisterSelf(HWND hWnd,int id)
{
    return 	RegisterHotKey( hWnd,id,m_wModifiers, m_wVirtualKeyCode) ;
}

void CHotKeyInfo::SaveToDisc(const CString& strSection,const CString& strKeyName ,CString &strFileName )
{
	if(this->m_bChanged)
	{
		m_bChanged = FALSE ;
		
		char Buffer[16];
		::WritePrivateProfileString(strSection,strKeyName+"Mod",::itoa(m_wModifiers,Buffer,10),strFileName);
		::WritePrivateProfileString(strSection,strKeyName+"VK",::itoa(m_wVirtualKeyCode,Buffer,10),strFileName);
	}
}

void CHotKeyInfo::ReadFromDisc(const CString& strSection,const CString& strKeyName ,CString &strFileName )
{
	m_wModifiers = ::GetPrivateProfileInt(strSection,strKeyName+"Mod",0 ,strFileName);
	m_wVirtualKeyCode = ::GetPrivateProfileInt(strSection,strKeyName+"VK",0 , strFileName);
	m_bChanged = TRUE ;
}

BOOL CHotKeyInfo::UnregisterHotKey(HWND hWnd, int id)
{
	return ::UnregisterHotKey(hWnd,id);
}
